<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="layout :: htmlhead"></head>
<head>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"
    <base th:href="@{/}">
    <!--<link rel="stylesheet" href="layui/css/layui.css">-->
</head>

<body class="layui-layout-body" style="overflow: auto;">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>更新记录</legend>
</fieldset>
<ul class="layui-timeline">
    <li class="layui-timeline-item">
        <i class="layui-icon layui-timeline-axis"></i>
        <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title">2020年2月16日</h3>
            <p>
                CIM统一发布平台1.0<i class="layui-icon"></i>
            </p>
        </div>
    </li>

    <li class="layui-timeline-item">
        <i class="layui-icon layui-timeline-axis"></i>
        <div class="layui-timeline-content layui-text">
            <div class="layui-timeline-title">过去</div>
        </div>
    </li>
</ul>

<!--
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
-->
<script type="text/javascript">
    /*文件&文件夹上传
    var file_input_more = document.getElementById('file_input_more');
    var file_input_one = document.getElementById('file_input_one');

    file_input_more.addEventListener('change', function() {
        var t_files = this.files;
        console.log(t_files);
        var str = '';
        var totalSize = 0.0;
        for (var i = 0, len = t_files.length; i < len; i++) {
            console.log(t_files[i]);
            str += "<"+(i+1)+">: "+t_files[i].name + '大小' + t_files[i].size / 1024 + 'KB \r\n';
            totalSize += t_files[i].size / 1024 / 1024;
        };
        var total = "共计："+t_files.length+"个文件,共计："+totalSize+"MB";
        document.getElementById('textArea').innerHTML = total+"\r\n"+str;
    }, false);
    file_input_one.addEventListener('change', function() {
        var t_files = this.files;
        console.log(t_files);
        var str = '';
        var totalSize = 0.0;
        for (var i = 0, len = t_files.length; i < len; i++) {
            console.log(t_files[i]);
            str += "<"+(i+1)+">: "+t_files[i].name + '大小' + t_files[i].size / 1024 + 'KB \r\n';
            totalSize += t_files[i].size / 1024 / 1024;
        };
        var total = "共计："+t_files.length+"个文件,共计："+totalSize+"MB";
        document.getElementById('textArea').innerHTML = total+"\r\n"+str;
    }, false);*/

    layui.use(['form', 'element', 'upload','jquery'], function() {
        var form = layui.form
            , layer = layui.layer
            , element = layui.element
            , $ = layui.jquery
            , upload = layui.upload;

        form.render('select');

        form.verify({
            newVersionNo: [/^[0-9]{1}\.[0-9]{1}\.[0-9]{1}\.[0-9]{1}$/, '版本格式不正确[1.0.0.1]！']
            ,curVersionNo: function(){
                var oldVersion = document.getElementById("curVersion").value;
                var newVersion = document.getElementById("newVersion").value;
                if(oldVersion == newVersion){
                    return "不能和当前版本一致！";
                }
            }
        });

        //选完文件后不自动上传
        form.on('select(fileType)', function(data) {
            var val = data.value;
            console.info(val);
            console.info(data);

            $.ajax({
                type: 'POST',
                url: "./index/getLastestVersion",
                //dataType: 'json',
                data: {fileType: val},//往后台发送的是data.field，即一个{name：value}的数据结构
                async: true,
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg('成功获取版本！', {icon: 1, time: 1000});
                        document.getElementById("curVersion").value = result.version;
                        document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+val+"当前版本："+result.version;
                    } else {
                        layer.msg('获取当前版本失败！' + result.msg, {icon: 2, time: 1000});
                        document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result.msg;
                    }
                },
                error: function (result, type) {
                    layer.msg('获取当前版本失败2！', {icon: 2, time: 1000});
                    document.getElementById("textArea").value = "\r\n"+writeCurrentDate()+result;
                }
            });
        });

        form.on('submit(formSubmit)', function(data) {
            if(!data.field.path){
                layer.alert("请先选择上传的文件！！", {
                    icon: 1,
                    time: 3000,
                    title: '错误'
                });
                return false;
            }

            $.ajax({
                type: 'POST',
                url: "./index/upload_save",
                data: data.field,
                async: true,
                success: function(result) {
                    console.log(result);
                    if (result.code == 0) {
                        layer.msg('保存成功', {icon: 1, time: 3000});
                    } else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 3000});
                    }
                },
                error: function(result, type) {
                    layer.msg('保存失败！', {icon: 2, time: 3000});
                }
            });
        });

        upload.render({
            elem: '#chooseFile'
            ,url: './index/upload_one'
            ,auto: true
            ,multiple: true
            ,drag: true
            ,accept: 'file' //普通文件
            //,exts: 'zip|rar|7z' //只允许上传压缩文件
            ,bindAction: '#uploadBtn'
            ,progress: function(e , percent) {
                    console.log("进度：" + percent + '%');
                    element.progress('progressBar',percent  + '%');
            }
            ,before: function(obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                console.log(res);
                layer.close(layer.msg());
                if(res.code == "fail"){
                    layer.msg("上传失败！！！");
                }
                if(res.code == "success"){
                    layer.msg("上传完成");
                    // 调用上传表单
                    document.getElementById("file_url").value = res.url;
                    document.getElementById("textArea").value += "\r\n"+writeCurrentDate()+"Upload-->"+res.url;
                }
            }
        });

    })

    function writeCurrentDate() {
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth();//得到月份
        var date = now.getDate();//得到日期
        var day = now.getDay();//得到周几
        var hour = now.getHours();//得到小时
        var minu = now.getMinutes();//得到分钟
        var sec = now.getSeconds();//得到秒
        var MS = now.getMilliseconds();//获取毫秒
        var week;
        month = month + 1;
        if (month < 10) month = "0" + month;
        if (date < 10) date = "0" + date;
        if (hour < 10) hour = "0" + hour;
        if (minu < 10) minu = "0" + minu;
        if (sec < 10) sec = "0" + sec;
        if (MS < 100) MS = "0" + MS;
        var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
        week = arr_week[day];
        var time = "";
        time = year + "/" + month + "/" + date + "/" + " " + hour + ":" + minu + ":" + sec +" ";
        //当前日期赋值给当前日期输入框中（jQuery easyUI）
        //$("#currentDate").html(time);
        //设置得到当前日期的函数的执行间隔时间，每1000毫秒刷新一次。
        var timer = setTimeout("writeCurrentDate()", 1000);
        return time;
    }

</script>
</body>
</html>